/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package network.Base;

import network.Base.Exceptions.IPParseException;
import java.util.regex.*;

/**
 *
 * @author Lega
 */
public class IPAddress {
    public IPAddress (String ip_)  throws IPParseException {
        if (ip_ == null) {
            throw new NullPointerException("ip is null");
        }

        Pattern ip_pat = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
        Matcher ip_matcher = ip_pat.matcher(ip_);
        if (ip_matcher.matches()) {
            ip = ip_.toString();
        } else {
            System.out.print("Unknown ip string format. Pattern was ignored\n");
            ip = "";
        }
    };
    private String ip;
    @Override
    public String toString() {
        if (ip != null) {
            return ip.toString();
        } else {
            return "";
        }
    }
}

